<template>
<!-- 图表三页面 -->
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">

          <a-col :md="8" :sm="24">
            <a-form-item label="单号">
              <a-input v-model="queryParam.orderNumber" placeholder="请输入单号"/>
            </a-form-item>
          </a-col>

          <a-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <!-- {{$businessEnum.ORG_TYPE_ENUM.PRIMARY_SUPPLIER.id}} -->
              <!--<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>-->
            </span>
          </a-col>

          <!-- <a-col :md="24" :sm="24">
            <a-form-item label="供应商：">
              <a-radio-group default-value="" button-style="solid" v-model="queryParam.orgIdSupplier">
                <a-radio-button value="">
                  全部
                </a-radio-button>
                <a-radio-button :value="id"
                                v-for="{id, name} in $util.getOrgList([this.$businessEnum.ORG_TYPE_ENUM.PRIMARY_SUPPLIER.id, this.$businessEnum.ORG_TYPE_ENUM.NORMAL_SUPPLIER.id])">
                  {{ name }}
                </a-radio-button>
              </a-radio-group>
            </a-form-item>
          </a-col>

          <a-col :md="24" :sm="24">
            <a-form-item label="归属公司：">
              <a-radio-group default-value="" button-style="solid" v-model="queryParam.orgIdCompany">
                <a-radio-button value="">
                  全部
                </a-radio-button>
                <a-radio-button :value="id" v-for="{id, name} in $util.getOrgList($businessEnum.ORG_TYPE_ENUM.COMPANY.id)">
                  {{ name }}
                </a-radio-button>
              </a-radio-group>

            </a-form-item>
          </a-col> -->

        </a-row>
      </a-form>
    </div>

    <s-table
      ref="table"
      size="default"
      :columns="columns"
      :data="loadData"
      :alert="true"
      :rowKey="(record) => record.code"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    >
      <span slot="orgName" slot-scope="text, record">
        {{record.orderType=='1479447062284427265'?
        record.targetOrgName:record.orderType=='1479447267234897921'?record.orgName:''}}
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="$refs.detailForm.show(record)">明细</a>
      </span>
    </s-table>

    <!--  发货单详情页  -->
    <detail-form ref="detailForm"/>

  </a-card>
</template>

<script>
import {STable} from '@/components'
import {page, pageAll} from '@/api/modular/main/emsorder/emsOrderManage'
import detailForm from './detailForm1'


export default {
  components: {
    STable,
    detailForm,
  },
  mounted(){

  },
  data() {
    return {
      advanced: false, // 高级搜索 展开/关闭
      queryParam: {},  // 查询参数
      columns: [
        {
          title: '序号',
          width: '80px',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          title: '单号',
          dataIndex: 'orderNumber'
        },
        {
          title: '时间',
          dataIndex: 'createTime'
        },
        {
          title: '供应商',
          dataIndex: 'orgName',
          scopedSlots: {customRender: 'orgName'}
        },
        // {
        //   title: '状态',
        //   dataIndex: 'executeStatus',
        //   customRender: (text, record, index) => {
        //     let es = this.$util.findExecuteStatusById(text)
        //     return es ? es.name : '未知状态'
        //   }
        // },
        {
          title: '操作',
          width: '250px',
          scopedSlots: {customRender: 'action'}
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        // this.queryParam.orderType = this.orderType
        console.log('this.$route',this.$route)
        this.materialType = this.$route.params.materialType
        this.queryParam.materialType = this.materialType
        if(this.$route.params.supplierId){
          if(this.$route.params.supplierId=='1502530915877912578' || this.$route.params.supplierId=='1502530819023044609'){
            this.queryParam.orgId = this.$route.params.supplierId
            this.queryParam.orderType = '1479447267234897921'
          }else if(this.$route.params.supplierId=='1498270916314161153'){
            this.queryParam.targetOrgType = this.$route.params.supplierId
            this.queryParam.orderType = '1479447062284427265'
          }
        }
        //获得time
        if(this.$route.params.year && this.$route.params.mounth){
          this.queryParam.time = this.$route.params.year + '-' + this.$route.params.mounth
        }else{
          this.queryParam.time = ''
        }
        //调接口,通过有没有supplierId来判断
        if(this.$route.params.supplierId){
          return page(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        }else{
          return pageAll(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        }
        
      },
      scheduleProductionVisible: false,
      selectedRowKeys: [],
      selectedRows: [],
      defaultExpandedKeys: [],
      replaceFields: {
        key: 'id',
      },
    }
  },
  computed: {
    orderType() {
      return this.$businessEnum.ORDER_TYPE_ENUM.deliverOrder.id
    },
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    handleOk() {
      this.$refs.table.refresh()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
  }
}
</script>

<style lang="less">
.table-operator {
  margin-bottom: 18px;
}

button {
  margin-right: 8px;
}
</style>
